package com.neusoft.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.neusoft.po.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import com.neusoft.po.Wallet;
import com.neusoft.po.WalletTrans;
import com.neusoft.service.WalletService;

@RefreshScope
@RestController
@RequestMapping("/WalletController")
public class WalletController {

    @Autowired
    private WalletService walletService;

    @PostMapping("/saveWallet/{userId}")
    public CommonResult<Integer> saveWallet(
            @PathVariable("userId") String userId) throws Exception{
        return new CommonResult<>(200,"sucess",walletService.saveWallet(userId));
    }

    @GetMapping("/getWalletByUserid/{userId}")
    public CommonResult<Wallet> getWalletByUserid(
            @PathVariable("userId") String userId) throws Exception{
        return new CommonResult<>(200,"sucess",walletService.getWalletByUserid(userId));
    }

    @PutMapping("/updateMoney/{userId}/{money}")
    public CommonResult<Integer> updateMoney(
            @PathVariable("userId") String userId,
            @PathVariable("money") BigDecimal money) throws Exception{
        return new CommonResult<>(200,"sucess",walletService.updateMoney(userId, money));
    }

    @PostMapping("/operate/{userId}/{amount}/{type}")
    public CommonResult<Integer> operate(
            @PathVariable("userId") String userId,
            @PathVariable("amount") BigDecimal amount,
            @PathVariable("type") Integer type) throws Exception{
        return new CommonResult<>(200,"sucess",walletService.operate(userId, amount, type));
    }

    @GetMapping("/listWalletTransByUserId/{userId}")
    public CommonResult<List> listWalletTransByUserId(
            @RequestParam("userId") String userId){
        List<WalletTrans> list = new ArrayList<>();
        list = walletService.listWalletTransByUserId(userId);
        return new CommonResult<>(200,"sucess",list);
    }

}
